#ifndef __UART1_H__
#define __UART1_H__
#include "stdio.h"	
#include "stm32f10x.h" 
#include "rtos.h"
#include "uartcommon.h"

#define UART1_TXBUFF_SIZE   1024
#define UART1_RXBUFF_SIZE   1024
#define UART1_RX_QUEUE_LEN  2
#define UART1_TX_INTERVAL 15    //ms
#define UART1_RX_INTERVAL 8  //ms



#ifndef TMDLY_BIT0
#define TMDLY_BIT0
#define UART1RXCTRBIT			0x001
#define UART1RXCTRTM			Timer3Ctr.time[0]
#define SETUART1RXDLY()		{TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE);\
														Timer3Ctr.devbit |= UART1RXCTRBIT;\
														UART1RXCTRTM = (u32)UART1_RX_INTERVAL;\
														TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);\
													}
#define RESETUART1RXDLY()	{DISABLE_INT();\
													Timer3Ctr.devbit &= ~UART1RXCTRBIT;\
													UART1RXCTRTM = 0;\
													ENABLE_INT();\
													}
#else
#error TMDLY_BIT0 has been defined!
#endif	//TMDLY_BIT0


#ifndef TMDLY_BIT1
#define TMDLY_BIT1
#define UART1TXCTRBIT			0x002
#define UART1TXCTRTM			Timer3Ctr.time[1]
#define SETUART1TXDLY()		{TIM_ITConfig(TIM3,TIM_IT_Update,DISABLE);\
														Timer3Ctr.devbit |= UART1TXCTRBIT;\
														UART1TXCTRTM = (u32)UART1_TX_INTERVAL;\
														TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);\
													}
#define RESETUART1TXDLY()	{DISABLE_INT();\
													Timer3Ctr.devbit &= ~UART1TXCTRBIT;\
													UART1TXCTRTM = 0;\
													ENABLE_INT();}
#else
#error TMDLY_BIT1 has been defined!
#endif	//TMDLY_BIT1




extern UARTSTRUCT MyUart1;
extern SemaphoreHandle_t  Binary_Uart1;
void Uart1_Init(u32 bound);






static void Uart1_TxDMAConfig(void);
static void Uart1TXDMAStart(u8 *senddata,u16 datalen);
static void Uart1_PutC(u8 udata);
static void Uart1_PutStrlen(u8 *senddata,u16 datalen);
static void Uart1_Printf(char* fmt,...) ;
static u8 Uart1_GetOneRxPkg(UART_RXINFO *pkginfo,u32 timetowait_ms);
static void Uart1_ReleaseOneRxPkg(UART_RXINFO *pkginfo);
static void Uart1_Var_Init(void);
static void Uart1_SendBeforCallBack(void);
static void Uart1_SendOverCallBack(void);
static void Uart1_StoreOneRxPkg(void);
static u8 Uart1_GetOneRxPkg(UART_RXINFO *pkginfo,u32 timetowait_ms);
static void Uart1_ReleaseOneRxPkg(UART_RXINFO *pkginfo);
static void Uart1_ReleaseAllRxPkg(void);
#endif


